package com.baosu.controller.back;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baosu.Exception.BusinessException;
import com.baosu.domain.Result;
import com.baosu.domain.Tag;
import com.baosu.service.TagService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/tag")
@Api(tags = "标签接口-后台")
public class TagController {

    @Autowired
    private TagService tagService;

    @GetMapping
    @ApiOperation(value = "标签下拉框")
    public Result getAllTag(){
        List<Tag> tags = tagService.list();
        return Result.ok(tags);
    }

    @GetMapping("/list")
    @ApiOperation(value = "分页列表,模糊搜索")
    public Result<Page> list(int page, int pageSize, String name){
        return tagService.pageTagList(page,pageSize,name);
    }

    @PostMapping
    @ApiOperation(value = "新增标签")
    public Result add(@RequestBody Tag tag){
        tagService.save(tag);
        return Result.ok(null);
    }

    @DeleteMapping
    @ApiOperation(value = "删除标签")
    public Result delete(@RequestParam List<Long> ids){
        return tagService.deleteTag(ids);
    }

    @PutMapping
    @ApiOperation(value = "修改标签")
    public Result edit(@RequestBody Tag tag){
        tagService.updateById(tag);
        return Result.ok(null);
    }

}
